from selenium.webdriver.common.by import By
from base.base_page import BasePage
from baseTools.my_logger import myLog

class OrgPage(BasePage):

    def create_org(self,tag_name,use_persion,use_power):
        """
        tag_name, user_persion, uer_power
        传递过来的数据用于添加功能
        """

        """self就是继承了对象库层的页面对象,use：self.my_click等方法"""
        myLog.info("执行操作层方法")
        # 进入通讯录界面
        tongxunlu = (By.XPATH,"//span[text()='通讯录']")
        self.my_click(ele=tongxunlu)
        # 点击标签
        tag_click = (By.XPATH,"//a[text()='标签' and @class='qui_btn ww_btn']")
        self.my_click(ele=tag_click)
        # 点击+号
        jiahao = (By.CSS_SELECTOR, "i[class*='member_colLeft_top_addBtn']")
        self.my_click(ele=jiahao)
        # # 点击-添加部门
        # biaoqian = (By.XPATH, "//a[text()='添加标签']")
        # self.my_click(ele=biaoqian)
        # 输入部门名称
        tagName = (By.CSS_SELECTOR,"input[placeholder='如行政/财务/华南区/领导']")
        self.my_input_send(ele=tagName,value=tag_name)
        # 选择使用人,存在就运行
        if use_persion:
            usePersion_click = (By.XPATH,"//a[.//span[contains(@class,'js_share_range_name') and text()='所有管理员']]")
            self.my_click(ele=usePersion_click)
            usePersion = (By.XPATH, f"//a[@on-click='setSharePublic' and text()='{use_persion}']")
            self.my_click(ele=usePersion)
        # 使用人权限
        if use_power:
            userPower_click = (By.XPATH, "//a[span[text()='仅使用'] and span[@class='ww_btn_Dropdown_arrow']]")
            self.my_click(ele=userPower_click)
            userPower = (By.XPATH,f"//a[@on-click='setPermRead' and contains(., '{use_power}')]")
            self.my_click(ele=userPower)
        # 点击确定
        myLog.info("点击确定")
        enter = (By.XPATH,"//a[text()='确定' and contains(@class, 'ww_btn_Blue')]")
        self.my_click(ele=enter)

